<?php
defined('PHPFOX') or exit('NO DICE!');

class Hoidap_Service_Category extends Phpfox_Service 
{

	/*lay danh sach section*/
	public function get($limit, $where =NULL)
	{
		if(!isset($where)){
			$where = " category_status=1 AND hdc.category_parent =0 ";
			//$where = " category_status=1 ";
		}

		mysql_query("set names'utf8'");
		return Phpfox::getLib('database')->select('hdc.category_name, hdc.category_id, hdc.category_image, hdc.category_parent')
		->from('phpfox_hoidap_category hdc')
		->where($where) 
		->order('hdc.category_order') 
		->limit($limit) 
		->execute('getSlaveRows');
	}
	
	public function getCatByParentCat($idParentCat)
	{
		mysql_query("set names'utf8'");
		return Phpfox::getLib('database')->select('hdc.category_name, hdc.category_id, hdc.category_image, hdc.category_parent')
		->from('phpfox_hoidap_category hdc')
		->where('category_status=1 and category_parent = '. $idParentCat) 
		->order('hdc.category_order') 
		->limit($limit) 
		->execute('getSlaveRows');
	}
	
	/*lay danh sach cach category theo id section*/
	public function selectListCategoryById($catid)
	{
		mysql_query("set names'utf8'");
		return Phpfox::getLib('database')->select('hdc.category_name, hdc.category_id, hdc.category_image ')
		->from('phpfox_hoidap_category hdc')
		->where(' category_status=1 AND hdc.category_parent ='.$catid) 
		->order('hdc.category_order') 
		->limit(10) 
		->execute('getSlaveRows');

	}
	
		/*lay danh sách câu hỏi nổi bật*/
	public function selectListCauHoi($parames = NULL)
	{

		$limit = $parames['limit'];
		mysql_query("set names'utf8'");
		if($parames['type']=='noibat')
		{
			//cau hoi noi bat						
			$cauhoinoibat = Phpfox::getLib('database')
				->select('hdch.cauhoi_id, hdch.title, hdch.time_stamp, hdch.total_view, u.user_name, u.user_image, hdc.category_name, hdch.category_id ')
				->from(Phpfox::getT('hoidap_category'), 'hdc')
				->join(Phpfox::getT('hoidap_cauhoi'), 'hdch', 'hdc.category_id = hdch.category_id')
				->join(Phpfox::getT('user'), 'u', 'u.user_id = hdch.user_id')
				->limit($limit)
				->where('hdch.post_status=1')
				->order('hdch.total_like DESC')
				->execute('getRows');
			
			return $cauhoinoibat;
					// echo "<pre>";
			// print_r($aUsuarios);
			// echo "</pre>";
			
		}else if($parames['type']=='moinhat')		
			{
				//cau hoi mới nhất
				$cauhoimoinhat = Phpfox::getLib('database')
					->select('hdch.cauhoi_id, hdch.title, hdch.time_stamp, hdch.total_view, u.user_name, u.user_image, hdc.category_name, hdch.category_id ')
					->from(Phpfox::getT('hoidap_category'), 'hdc')
					->join(Phpfox::getT('hoidap_cauhoi'), 'hdch', 'hdc.category_id = hdch.category_id')
					->join(Phpfox::getT('user'), 'u', 'u.user_id = hdch.user_id')
					->limit($limit)
					->where('hdch.post_status=1')
					->order('hdch.time_stamp DESC')
					->execute('getRows');
						
				return $cauhoimoinhat;
		
			}else{
				// cau hoi theo chu de
			}




	}
	
}

?>